package com.afkt.project.ui.pageslider;

import com.afkt.project.util.LogUtils;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.PageSliderProvider;

import java.util.ArrayList;
import java.util.List;

public class PageSliderAdapter extends PageSliderProvider {

    private final static String TAG = "PageSliderAdapter";
    private List<Component> pages;


    public PageSliderAdapter(ArrayList<Component> pages) {
        this.pages = pages;
        LogUtils.error(TAG, "pages:" + pages.size());
    }

    @Override
    public int getCount() {
        return pages == null ? 0 : pages.size();
    }


    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        componentContainer.addComponent(pages.get(i));
        LogUtils.error(TAG, i + "");
        return componentContainer;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent(pages.get(i));
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return component == o;
    }

}
